/**
 * Created by root on 5/30/16.
 */

function submit_login_form() {
    $('#id_login_form').validate({
        rules: {
            username: {
                required: true,
                maxlength: 50
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 25
            },
            validation_code: {
                required: true,
                minlength: 4,
                maxlength: 4
            }
        },
        messages: {
            username: {
                required: "用户名不能为空",
                maxlength: "用户名不能多与50个字符"
            },
            password: {
                required: "密码不能为空",
                minlength: "密码不能低于6位",
                maxlength: "密码长度不能多于25位"
            },
            validation_code: {
                required: "请输入4位验证码",
                minlength: "请输入4位验证码",
                maxlength: "请输入4位验证码"
            }
        },

        submitHandler: function (form) {
            $.post("/APKManager/login/", {
                    username: form.username.value,
                    password: form.password.value,
                    validation_code: form.validation_code.value
                },
                function (data) {
                    if (data.rltcode != 0) {
                        var err = new error_dialog();
                        err.show("登录错误", data.rltmsg, 1000, reload = true);
                    } else {
                        <!--location.url = data.object.url;-->
                        // $.get(data.object.url);
                        window.location.href = data.object.url;
                    }
                });
        }
    });
}

function check_image(obj, width, height) {
    if (obj.width() > width || obj.height() > height) {
        alert("图片尺寸应小于"+width+"x"+height);
        var err_label = "<span name='err_message'style='color:red'>请选择正确格式的图像</span>";
        obj.after(err_label);
        return false;
    } else {
        var nextobj = obj.after();
        if (nextobj.name == err_id) {
            nextobj.remove();
        }
    }
    return true;
}

function submit_account_form() {
    $("#id_account_form").validate({
        rules: {
            company: { required:true},
            representative: { required: true},
            reg_address: {required: true},
            province: {required: true},
            city: {required:true},
            postcode: {reqired: true, minlength:6, maxlength:6},
            license:{required: true},
            bank_account_name:{required:true},
            bank_name:{required:true},
            bank_account:{reqiured:true},
            taxpayer_id_no:{required:true},
            bus_inf_name: {reqired:true},
            bus_telephone_no:{required:true, digits: true},
            bus_mail:{required: true, email: true},
            eng_inf_name:{required:true},
            eng_telephone_no:{required:true, digits:true},
            eng_mail:{required: true, email:true}
        },

        messages: {
            company:{required: "请正确输入公司名称"},
            representative:{required: "请输入法人代表名称"},
            reg_address:{required:"请输入注册地址"},
            province: {required: "请选择公司所在省"},
            city:{required: "请选择公司所在市"},
            postcode:{required: "请正确输入邮政编码"},
            license:{required: "请提交营业执照"},
            bank_account_name:{required:"请填写银行账户名称"},
            bank_name:{required:"请选择银行"},
            bank_account:{required: "请填写银行账户"},
            taxpayer_id_no:{required: "请填写纳税人识别号"},
            bus_inf_name:{required:"请填写业务接口人姓名"},
            bus_telephone_no: {required:"请填写义务接口人电话"},
            bus_mail:{required:"请填写业务接口人邮件"},
            eng_inf_name: {required:"请填写技术接口人姓名"},
            eng_telephone_no:{required:"请填写技术接口人电话"},
            eng_mail:{required:"请填写技术接口人邮件"},
        },



        // submitHandler: function(form) {
        //     post_data = {
        //         company: form.company.value,
        //         representative: form.representative.value,
        //         reg_address: form.reg_address.value,
        //         province: form.province.selectedIndex,
        //         city: form.city.selectedIndex,
        //         postcode: form.postcode.value,
        //         license: form.license.value,
        //         bank_account_name:form.bank_account_name.value,
        //         bank_name:form.bank_name.selectedIndex,
        //         bank_account:form.bank_account.value,
        //         taxpayer_id_no:form.taxpayer_id_no.value,
        //         bus_inf_name:form.bus_inf_name.value,
        //         bus_telephone_no:form.bus_telephone_no.value,
        //         bus_mail:form.bus_mail.value,
        //         eng_inf_name:form.eng_inf_name.value,
        //         eng_telephone_no:form.eng_telephone_no.value,
        //         eng_mail:form.eng_mail.value
        //     };
        //
        //     if (form.tax_reg_ca.files.length > 0) {
        //         post_data.tax_reg_ca = form.tax_reg_ca.files[0];
        //     }
        //
        //     if (form.bank_license.files.length > 0) {
        //         post_data.bank_license = form.bank_license.files[0];
        //     }
        //
        //     if (form.others.length > 0) {
        //         post_data.others = form.others.files[0];
        //     }
        //     // var formData = new FormData($('#id_account_form')[0]);
        //     $('#id_account_form').submit();
        //
        //     $.post("/APKManager/cp/handler/submit_account", post_data, function (data) {
        //         if (data.rltcode == 0) {
        //             var msgdiv = "<div class='row'> <div class='col-sm-12'><div class='panel submit_return'><div><h3>信息已提交，我们将在5个工作日内完成审核</h3><p>审核结果将以邮件形式进行通知，请业务接口人及时查收<br/>通过审核后即可进行上传游戏操作</p></div></div></div></div>"
        //             $("#id_account_info").remove();
        //             $("#id_navbar").after(msgdiv);
        //         } else {
        //
        //         }
        //     });
        // }
    });
}